// JavaScript Document

var PeopleMedia = PeopleMedia || {};
PeopleMedia.PhotoUpload = new function () {
    this.ableToClickSubmit = false;
    this.ableToClickSubmitSaveTitle = false;
    this.HighlightUpload = function () {
        var uploadFileName = null;


        PeopleMedia.PhotoUpload.ableToClickSubmit = true;
        $jq("#UploadPhotoButton").removeClass("buttonunavailable");
        $jq("#invalidFileSelected").hide();
        

        for (var i = 1; i <= 4; i++) {
            if (i > 1) {
                uploadFileName = $jq("#uploadFile" + i);
            } else {
                uploadFileName = $jq("#uploadFile");
            }

            if (uploadFileName.val() != null) {
                var tempUploadFileName = uploadFileName.val();
                if (tempUploadFileName.toLowerCase().indexOf(".jpg") >= 0 || tempUploadFileName.toLowerCase().indexOf(".jpeg") >= 0 || tempUploadFileName.toLowerCase().indexOf(".gif") >= 0 || tempUploadFileName.toLowerCase().indexOf(".png") >= 0 || tempUploadFileName.toLowerCase().indexOf(".bmp") >= 0) {
                    uploadFileName.removeClass("invalidFileSelected");
                } else if (tempUploadFileName.length > 0) {
                    PeopleMedia.PhotoUpload.ableToClickSubmit = false;
                    uploadFileName.addClass("invalidFileSelected");
                    $jq("#UploadPhotoButton").addClass("buttonunavailable");
                    $jq("#invalidFileSelected").show();
                }
            }
        }


    };
    this.TargetSaveTitle = function (mediaId) {
        var saveTitleTextbox = $jq("#SaveTitle" + mediaId + " .inputtextmedium");
        if (saveTitleTextbox.val() == 'Add a photo caption') {
            saveTitleTextbox.val("");
        }
    };
    this.HighlightSaveTitle = function (mediaId) {
        var saveTitleSubmitButton = $jq("#Submit" + mediaId);
        saveTitleSubmitButton.text("Save");
        saveTitleSubmitButton.attr("title", "Save");
        saveTitleSubmitButton.removeClass("buttonunavailable");
        PeopleMedia.PhotoUpload.ableToClickSubmitSaveTitle = true;
    };
    this.SaveTitle = function (mediaId) {
        if (PeopleMedia.PhotoUpload.ableToClickSubmitSaveTitle) {
            buttonDetails = $jq("#Submit" + mediaId);
            buttonDetails.addClass("buttonunavailable");
            buttonDetails.text("Processing...");
            $jq("#SaveTitle" + mediaId).submit();
            PeopleMedia.PhotoUpload.ableToClickSubmit = false;
        }
    };
    this.UploadPhotos = function (buttonId) {
        if (PeopleMedia.PhotoUpload.ableToClickSubmit) {
            buttonDetails = $jq("#" + buttonId);
            buttonDetails.addClass("buttonunavailable");
            buttonDetails.text("Processing...");
            $jq("#pmiuForm").submit();
            PeopleMedia.PhotoUpload.ableToClickSubmit = false;
        }
    };
    this.ShowDeleteOverlay = function (mediaId) {
        $jq("#deleteOverlay" + mediaId).show();
    };
    this.CloseDeleteOverlay = function (mediaId) {
        $jq("#deleteOverlay" + mediaId).hide();
    };
    this.ConfirmDeleteOverlay = function (mediaId) {
        window.location.replace(FRONT_SITE_URL+"user/profile/MediaUpload?type=1&mediaid=" + mediaId);
    };
    this.ShowInProfile = function (mediaId) {
        $jq("#ShowInProfile" + mediaId).submit();
    };
    this.CheckTextboxInput = function (textBox) {
        if (textBox.value.length > 25) {
            textBox.value = textBox.value.substring(0, 25);
        }
    };
    this.DefaultTitleTextbox = function (textBox, textBoxDefault) {
        var defaultText = $jq("#" + textBoxDefault).val();
        $jq("#" + textBox).val(defaultText);
    };


};

$jq(document).ready(function() {
	// hide ingredients for a great spread
	$jq(".largestclosebtn").click(function() { $jq(".popupshow ").hide(); });
	// show ingredients for a great spread
	$jq(".launchlargeoverlay").click(function () {
	    $jq(".popupshow ").show();
	    $jq("div[class^='deletephotooverlayplace']").hide();
	});
 });

